package com.hound.service.impl;

import com.hound.config.datasource.TargetDataSource;
import com.hound.mapper.TUserMapper;
import com.hound.mapper.UserMapper;
import com.hound.model.TUser;
import com.hound.model.User;
import com.hound.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by lupeng on 2018/3/31.
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private TUserMapper tuserMapper;

    @Override
    @Transactional
    public Integer addUser(User user) {
        userMapper.insertSelective(user);
//        if (true){
//            int i = 1/0;
//        }
        System.out.println(user.getId());
        return Long.valueOf(user.getId()).intValue();
    }

    @Override
    @TargetDataSource("ds1")
    public Integer addTUser(TUser tUser){
        tuserMapper.insert(tUser);
        return Long.valueOf(tUser.getId()).intValue();
    }
}
